//
//  SYBaiBanFuDaoViewController.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/12/25.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYBaiBanFuDaoViewController.h"
#import "TICDef.h"
#import "SYBaiBanTabView.h"
#import "UIImage+SY.h"
#import "SYColorViewController.h"//选择画笔颜色
#import "SYBaiBanGongJuViewController.h"//工具
#import "SYBoardZiYuanViewController.h"
#import "SYBaiBanDeleteViewController.h"
#import "SYIMStudentsView.h"
#import "SYBaiBanTopView.h"
#import "SYBaiBanModel.h"
#import "SYBaiBanColorViewController.h"
#import "SYBaiBanColorViewController.h"
#import "SYBaiBanTimeView.h"
#import "SYBaiBanCuXiViewController.h"
#import "ResourceViewController.h"
#import "SYChooseImageViewController.h"


//允许u学生发言
NSInteger const kGFYunXuType = 450;
//结束上课
NSInteger const kGFJieShuType = 430;
//推出房间
NSInteger const kGFTuiChuType = 420;
@interface SYBaiBanFuDaoViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate,TEduBoardDelegate,SYIMStudentsViewDelegate,SYBaiBanColorViewDelegate,TICEventListener, TICMessageListener,TRTCCloudDelegate,SYBaiBanCuXiViewControllerDelegate,SYBoardZiYuanViewControllerDelegate>
@property (weak, nonatomic) IBOutlet UIView *funtView;//功能view
//@property (strong, nonatomic) SYColorViewController *colorVC;
@property (weak, nonatomic) IBOutlet UILabel *stateLab;
@property (weak, nonatomic) IBOutlet SYBaiBanTabView *bbFuntView;
@property (strong, nonatomic) SYBaiBanGongJuViewController *gongJuVC;//工具
@property (strong, nonatomic) UIImagePickerController *imagePicker;//图片选择
@property (strong, nonatomic) SYBoardZiYuanViewController *zyVC;//资源
@property (strong, nonatomic) SYBaiBanDeleteViewController *deleteVC;//删除
@property (strong, nonatomic) TIMConversation *conversation;//!<群聊回话
@property (strong, nonatomic) SYIMStudentsView *studentsView;//学生
@property (weak, nonatomic) IBOutlet SYBaiBanTopView *bbTopView;
@property (strong, nonatomic) SYBaiBanColorViewController *colorVC;
@property (weak, nonatomic) IBOutlet SYBaiBanTimeView *timerView;
@property (strong, nonatomic) SYBaiBanCuXiViewController *cxVC;//画笔粗细vc
@property (weak, nonatomic) IBOutlet UIButton *studentBtn;//学生列表
@property (weak, nonatomic) IBOutlet UIButton *starRecordingBtn;//开始录制
@property (weak, nonatomic) IBOutlet UIButton *extBtn;//结束辅导

@property (weak, nonatomic) IBOutlet UIView *bbCountView;

@property (strong, nonatomic) TEduBoardController *boardController;

@property (strong, nonatomic) NSArray *numberArr;
@property (weak, nonatomic) IBOutlet UILabel *pageNumberLab;//当前页面
@property (weak, nonatomic) IBOutlet UILabel *zongNumberLab;//总页面
@property (assign, nonatomic) NSInteger teacherRecordId;//教师id
@property (copy, nonatomic) NSString *infoId;//录制视频得列表
@property (weak, nonatomic) IBOutlet UILabel *wifiLab;//信号状态
@property (strong, nonatomic) ResourceViewController *resourceVC;


@property (assign, nonatomic) NSInteger luzhiIndex;//录制状态记录 0 开始录制 1 暂停 2 恢复录制
@end

@implementation SYBaiBanFuDaoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self initKitView];
    
    //接受到消息的通知
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(onNewMessageNotification:) name:TUIKitNotification_TIMMessageListener object:nil];
    //选择资源接受到心得资源
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(onDowloadPPTNotification:) name:@"xuanzeziyuanwangge"
                                               object:nil];
    
    _luzhiIndex = 0;
    
    
}


#pragma mark - 初始化view
- (void)initKitView {
    
    [self boardLoginView];
    
    
    //下方导航栏的方法
    __weak typeof(self) weakSelf = self;
    
    self.bbFuntView.block = ^(SYBaiBanSelectType type, UIButton * _Nonnull btn) {
        [weakSelf selectTabType:type selectBtn:btn];
    };
    
   _conversation = [[TIMManager sharedInstance] getConversation:TIM_GROUP receiver:self.tecentRoom];
    
    
    //上方top 返回选中得白板文件id
    _bbTopView.block = ^(NSString * _Nonnull fileId) {
        //切换到文件
        [weakSelf.boardController switchFile:fileId];
        
    };
    
    if (self.isChat == YES) {
        self.studentBtn.hidden = YES;
        self.starRecordingBtn.hidden = NO;
        [self.extBtn setTitle:@"结束录制" forState:UIControlStateNormal];
    } else {
        self.studentBtn.hidden = NO;
        self.starRecordingBtn.hidden = YES;
        //学生列表
        _studentsView = [[NSBundle mainBundle] loadNibNamed:@"SYIMStudentsView" owner:nil options:nil].firstObject;
        _studentsView.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
        _studentsView.delegate=  self;
        [_studentsView getGroupMembersStudent:self.fdbId];
        _studentsView.hidden = YES;
        [self.view addSubview:_studentsView];
        [_studentsView bringSubviewToFront:self.view];
        [self.studentsView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.view.mas_right);
            make.bottom.equalTo(self.view);
            make.top.equalTo(self.view.mas_top).offset(60);
            make.width.mas_equalTo(150);
        }];
    }
    
    
}

#pragma mark - 按钮方法
//开始录制
- (IBAction)starBtnClick:(UIButton *)sender {
    
    if (_luzhiIndex == 0) {
        //开始录制
        //    开始录制
        [self startRecord];
    } else if (_luzhiIndex == 1) {
        [self pauseRecord];//暂停
    } else if (_luzhiIndex == 2) {
        [self huifuRecord];
    }
    

}




//结束课堂
- (IBAction)jieshuKeTangBtnClick:(UIButton *)sender {
    
    
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确定退出?" message:@"" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self exitClassTutorship];
    }];
    
    [alert addAction:cancel];
    [alert addAction:confirm];
    
    [self presentViewController:alert animated:YES completion:nil];
    
}

- (void)exitClassTutorship {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[TICManager sharedInstance] removeEventListener:self];
    [[TICManager sharedInstance] removeMessageListener:self];
    [self stopRecord];
    [self.timerView stopTimer];
    if (self.isChat !=YES) {
        //白板辅导结束
        [self teacherEnterClass];
    } else {
        
        [MBProgressHUD mj_showMessage:@"正在退出课堂"];
        //群聊辅导结束
        [[TICManager sharedInstance] quitClassroom:YES callback:^(TICModule module, int code, NSString *desc) {
            if(code == 0){
                if (self.isWeiKe == YES) {//微课录制进入
                    [MBProgressHUD mj_hideHUD];
                    [self dismissViewControllerAnimated:YES completion:^{
                        if (self.infoId.length > 0) {
                            NSDictionary *dict = @{@"path":self.infoId};
                            [[NSNotificationCenter defaultCenter] postNotificationName:@"luzhiweike" object:nil userInfo:dict];
                        }
                        
                    }];
                    
                    
                }  else {
                    if (self.newWeiKe == YES) {
                    [MBProgressHUD mj_hideHUD];
                    //退出课堂成功
                    [self dismissViewControllerAnimated:YES completion:^{
                        if (self.infoId.length > 0) {
                            NSDictionary *dict = @{@"path":self.infoId};
                            [[NSNotificationCenter defaultCenter] postNotificationName:@"newWeiKeLuZhi" object:nil userInfo:dict];
                        }
                    }];
                        
                    } else {
                        [NSObject executeRunloop:^{
                            [MBProgressHUD mj_hideHUD];
                            //退出课堂成功
                            [self dismissViewControllerAnimated:YES completion:^{
                                if (self.infoId.length > 0) {
                                    NSDictionary *dict = @{@"path":self.infoId};
                                    [[NSNotificationCenter defaultCenter] postNotificationName:@"faSongLuPing" object:nil userInfo:dict];
                                }
                            }];
                            
                        } afterDelay:5];
                    }
                    
                }
                
            }
            else{
                //退出课堂失败
                [MBProgressHUD mj_hideHUD];
                [MBProgressHUD mj_showMessage:@"退出课堂失败"];
            }
        }];
    }
}

//学生列表
- (IBAction)studentBtnClick:(UIButton *)sender {
    _studentsView.hidden = !_studentsView.hidden;
}
//上一页
- (IBAction)shangYeBtnClick:(UIButton *)sender {
    [_boardController prevStep];
    [self pageZhanShi];
}
//下一页
- (IBAction)xiaYeBtnClick:(UIButton *)sender {
    [_boardController nextStep];
    [self pageZhanShi];
}
- (void)onTEBSwitchFile:(NSString *)fileId {
    //获取当前文件夹的数组
    [self pageZhanShi];
}
#pragma mark - 集成白班
- (void)boardLoginView {
//    NSString *userSig = @"IOS01";//_userSig;
//    NSString *userName = @"eJyrVgrxCdYrSy1SslIy0jNQ0gHzM1NS80oy0zLBwp7*wQaGUInilOzEgoLMFCUrQxMDAyMzS1MTS4hMakVBZlEqUNzU1NTIwMAAIlqSmQsWMzczM7UwszSGmpKZDjTXOcPdt9g9xz2wPKjYwtLXLCkoxyO1wiXcK8nNPCPfLEbfxNEkRj*5qNw7NyndVqkWAClCMTQ_";//_userName;
//    _roomId = @"2";
    
    NSString *userSig = _userSig;
    NSString *userName = _userName;
    [MBProgressHUD mj_showMessage:@"正在加入课堂..."];
    //登录
    [[TICManager sharedInstance] login:userName userSig:userSig callback:^(TICModule module, int code, NSString *desc) {
        [self joinClassroomWithOption];
    }];
    
    
    
}
//加入课堂
- (void)joinClassroomWithOption {
    //先创建，如果创建过直接加入10025，如果没创建过创建成功后加入
//    [MBProgressHUD mj_showLoading];
    //先写死，后期是roomId
//    _roomId = @"2";
    [[TICManager sharedInstance] createClassroom:[_roomId intValue] classScene:TIC_CLASS_SCENE_VIDEO_CALL callback:^(TICModule module, int code, NSString *desc) {
        [MBProgressHUD mj_hideHUD];
        if (code == 0) {
            //创建成功 - 加入
            [self onJoinClass];
        } else {
            if (code == 10021 || code == 10025) {//课堂已经被创建 加入
                
                [self onJoinClass];
            } else {//创建失败
                [MBProgressHUD zr_showError:@"创建课堂失败"];
                [NSObject executeRunloop:^{
                    [self dismissViewControllerAnimated:YES completion:^{
                        
                    }];
                } afterDelay:1];
            }
        }
    }];
    
}
//加入课堂
- (void)onJoinClass {
    TICClassroomOption *option = [[TICClassroomOption alloc] init];
//    _roomId = @"2";
    option.classId = [_roomId intValue];
    option.roleType = TIC_ROLE_TYPE_ANCHOR;//设置成角色是教师
    option.classScene = TIC_CLASS_SCENE_VIDEO_CALL;
    
    [[TICManager sharedInstance] addMessageListener:self];
    [[TICManager sharedInstance] addEventListener:self];
    
    
    [[TICManager sharedInstance] joinClassroom:option callback:^(TICModule module, int code, NSString *desc) {
        [MBProgressHUD mj_hideHUD];
        if (code == 0) {//加入成功
            //加入成功s初始化白板
            
            [self initBoardView];
//          TOP 先注销了，测试的时候用上
            if (self.isChat != YES) {
                //更新老师上课状态
                [self teacherClass];
                //发送推送
                [self tutorClassPushMsg];
//                开始录制
                [self startRecord];
            }
            
//
            
        } else {
            //加入失败
            [MBProgressHUD zr_showError:@"加入课堂失败"];
            [NSObject executeRunloop:^{
                [self dismissViewControllerAnimated:YES completion:^{
                    
                }];
            } afterDelay:1];
        }
    }];
}
//初始化白板
- (void)initBoardView {
    //白板视图

    [[[TICManager sharedInstance] getBoardController] addDelegate:self];
    UIView *boardView = [[[TICManager sharedInstance] getBoardController] getBoardRenderView];
    _boardController = [[TICManager sharedInstance] getBoardController] ;
    [self.bbCountView addSubview:boardView];
    [boardView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.mas_equalTo(self.bbCountView);
    }];
    [self.boardController setBrushThin:9];
    
    
    
}
#pragma mark - 白板得代理
//图片加载完成的回掉
- (void)onTEBSetBackgroundImage:(NSString *)url {
    [MBProgressHUD mj_hideHUD];
    
}

- (void)onTEBImageStatusChanged:(NSString *)boardId url:(NSString *)url status:(TEduBoardImageStatus)status {
    [MBProgressHUD mj_hideHUD];
}

- (void)onTEBFileTranscodeProgress:(TEduBoardTranscodeFileResult *)result path:(NSString *)path errorCode:(NSString *)errorCode errorMsg:(NSString *)errorMsg {
    
    
    if (result.status == TEDU_BOARD_FILE_TRANSCODE_FINISHED) {//转码成功
        [MBProgressHUD mj_hideHUD];
        [_boardController addTranscodeFile:result];
        self.stateLab.text = @"转码成功";
        [NSObject executeRunloop:^{
            self.stateLab.hidden = YES;
        } afterDelay:5];
        [self obtainBoarNumber];
    } else if (result.status == TEDU_BOARD_FILE_TRANSCODE_ERROR) {//转码错误
        [MBProgressHUD mj_hideHUD];
        [MBProgressHUD zr_showError:@"转码失败，请重试~！"];
        self.stateLab.text = @"转码失败";
        [NSObject executeRunloop:^{
            self.stateLab.hidden = YES;
        } afterDelay:3];
    } else {
        
    }
    
    
    
}
/**
 * 白板历史数据同步完成回调
 */
- (void)onTEBHistroyDataSyncCompleted {
    //获取白板文件页得列表
    [self obtainBoarNumber];
    
    [_boardController setDataSyncEnable:YES];
    [[[TICManager sharedInstance] getTRTCCloud] startLocalAudio];
    if (!self.isChat) {
        //开始计时
        [self.timerView startTimer];
    }
    
    //实时音视频 -- 监控网络
//    [TRTCCloud sharedInstance].delegate = self;
}
/**
 * 删除白板页回调
 * @param boardIds       删除的白板页IDs
 * @param fileId        删除的白板页所属的文件ID
 */
- (void)onTEBDeleteBoard:(NSArray *)boardIds fileId:(NSString *)fileId {
    
}

//加入课堂
-(void)onTICMemberJoin:(NSArray*)members {
    _studentsView.enterStr = members.firstObject;
    
}
//退出课堂
-(void)onTICMemberQuit:(NSArray*)members {
    _studentsView.quitStr = members.firstObject;
    
}





#pragma mark - 选中导航栏的方法
- (void)selectTabType:(SYBaiBanSelectType)type selectBtn:(UIButton *)btn {
    switch (type) {
        case SYBaiBanSelectTypeXiJian://新建
            [_boardController addBoardWithBackgroundImage:nil];
            [self pageZhanShi];
            break;
        case SYBaiBanSelectTypeYiDong://移动
            [_boardController setToolType:TEDU_BOARD_TOOL_TYPE_ZOOM_DRAG];
            break;
        case SYBaiBanSelectTypeHuaBi://画笔
            [self selectBrushCuXiHuaBi:btn];
            break;
        case SYBaiBanSelectTypeHuaBiColor://画笔颜色
            [self selectBrushColorInteraction:btn];
            break;
        case SYBaiBanSelectTypeWenZi://文字输入
            [_boardController setToolType:TEDU_BOARD_TOOL_TYPE_TEXT];
            break;
        case SYBaiBanSelectTypeXiangPi://橡皮擦
            [_boardController setToolType:TEDU_BOARD_TOOL_TYPE_ERASER];
            break;
        case SYBaiBanSelectTypeGongJu://工具
            [self selectBrushGongJuInteraction:btn];
            break;
        case SYBaiBanSelectTypeQingKong://清空
            [self tutorDeleteInteraction:btn];
            break;
//        case SYBaiBanSelectTypeWangGe://插入网格
//
//            break;
        case SYBaiBanSelectTypeChaRuWenJian://插入文件
            [self tutorResourceInfointeraction:btn];
            break;
        case SYBaiBanSelectTypeChaRuTuPian://插入图片
        {
                        __weak typeof(self) weakSelf = self;
                        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"选择图片" preferredStyle:UIAlertControllerStyleAlert];
                        
                        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                            // 选择图片
                            [self selectBrushChaRuTuPianInteraction:btn];

                        }];
                        
                        UIAlertAction *setAction = [UIAlertAction actionWithTitle:@"线上" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                            
                            SYChooseImageViewController *VC = [[SYChooseImageViewController alloc]init];
                            VC.modalPresentationStyle = UIModalPresentationOverFullScreen;
                            
                            VC.chooseImage = ^(NSString * _Nonnull imageUrl) {
                                
            //                    UIImage *image = [UIImage ]
                                [NSObject executeRunloop:^{
                                    [MBProgressHUD mj_showMessage:@"正在插入图片..."];
                                } afterDelay:0.1];
                                [weakSelf.boardController setBackgroundImage:imageUrl mode:TEDU_BOARD_IMAGE_FIT_MODE_CENTER];
                                

                            };
                            [self presentViewController:VC animated:YES completion:nil];


                        }];
                        
                        [alertController addAction:okAction];
                        [alertController addAction:setAction];
                        
                        [self presentViewController:alertController animated:YES completion:nil];
                        
            
        }
            break;
            
        default:
            break;
    }
}
#pragma mark - 选择画笔颜色
- (SYBaiBanColorViewController *)colorVC {
    if (!_colorVC) {
        _colorVC = [[SYBaiBanColorViewController alloc] init];
        _colorVC.delegate = self;
    }
    return _colorVC;
}
#pragma mark - 画笔粗细
- (SYBaiBanCuXiViewController *)cxVC {
    if (!_cxVC) {
        _cxVC = [[SYBaiBanCuXiViewController alloc] init];
    }
    return _cxVC;
}
- (void)selectBrushCuXiHuaBi:(UIButton *)interaction {
    //弹出试图的参照试图
    //  弹出视图的显示样式
    self.cxVC.modalPresentationStyle = UIModalPresentationPopover;
    [_boardController setToolType:TEDU_BOARD_TOOL_TYPE_PEN];
    //  1、弹出视图的大小
    self.cxVC.preferredContentSize = CGSizeMake(200, 60);
    self.cxVC.popoverPresentationController.sourceView = interaction;
    self.cxVC.popoverPresentationController.sourceRect = interaction.bounds;
    //箭头得方向
    self.cxVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionDown;
    self.cxVC.popoverPresentationController.backgroundColor = [UIColor whiteColor];
    self.cxVC.delegate = self;
    [self presentViewController:self.cxVC animated:YES completion:nil];
    
}

- (void)selectCuXiType:(NSInteger)index {
    __weak typeof(self) weakSelf = self;
    [self dismissViewControllerAnimated:YES completion:^{
        if (index == 0) {
            [weakSelf.boardController setBrushThin:9];
        } else if (index == 1) {
            [weakSelf.boardController setBrushThin:36];
        } else {
            [weakSelf.boardController setBrushThin:72];
        }
    }];
}



//选择画笔颜色
- (void)selectBrushColorInteraction:(UIButton *)interaction {
//    self.colorVC = [[SYColorViewController alloc] init];
    //弹出试图的参照试图
    //  弹出视图的显示样式
    self.colorVC.modalPresentationStyle = UIModalPresentationPopover;
    
    //  1、弹出视图的大小
    self.colorVC.preferredContentSize = CGSizeMake(200, 175);
    self.colorVC.popoverPresentationController.sourceView = interaction;
    self.colorVC.popoverPresentationController.sourceRect = interaction.bounds;
    //箭头得方向
    self.colorVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionDown;
    self.colorVC.popoverPresentationController.backgroundColor = [UIColor whiteColor];
    
    [self presentViewController:self.colorVC animated:YES completion:nil];
    

}
- (void)selectItemColorHex:(NSString *)colorHex {
    [[[TICManager sharedInstance] getBoardController] setBrushColor:[UIColor colorWithHexString:colorHex]];
    [[[TICManager sharedInstance] getBoardController] setTextColor:[UIColor colorWithHexString:colorHex]];
    
    [self.colorVC dismissViewControllerAnimated:YES completion:^{
    }];

}


#pragma mark - 工具

- (SYBaiBanGongJuViewController *)gongJuVC {
    if (!_gongJuVC) {
        _gongJuVC = [[SYBaiBanGongJuViewController alloc] init];
    }
    return _gongJuVC;
}

- (void)selectBrushGongJuInteraction:(UIButton *)interaction {
    //self.gongJuVC = [[SYBaiBanGongJuViewController alloc] init];
    //弹出试图的参照试图
    //  弹出视图的显示样式
    self.gongJuVC.modalPresentationStyle = UIModalPresentationPopover;
    [_boardController setToolType:TEDU_BOARD_TOOL_TYPE_RECT];
    //  1、弹出视图的大小
    self.gongJuVC.preferredContentSize = CGSizeMake(200, 60);
    self.gongJuVC.popoverPresentationController.sourceView = interaction;
    self.gongJuVC.popoverPresentationController.sourceRect = interaction.bounds;
    //箭头得方向
    self.gongJuVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionDown;
    self.gongJuVC.popoverPresentationController.backgroundColor = [UIColor whiteColor];
    
    [self presentViewController:self.gongJuVC animated:YES completion:nil];
    
    __weak typeof(self) weakSelf = self;
    
    self.gongJuVC.gongJBlock = ^(NSInteger index) {//0：激光笔 1：直线 2：矩形 3：圆形
        [weakSelf.gongJuVC dismissViewControllerAnimated:YES completion:^{
            //得到要画的样式，复制
            NSInteger boardToolType;
            if (index == 0) {
                boardToolType = TEDU_BOARD_TOOL_TYPE_LASER;
            } else if (index == 1) {
                boardToolType = TEDU_BOARD_TOOL_TYPE_LINE;
            } else if (index == 2) {
                boardToolType = TEDU_BOARD_TOOL_TYPE_RECT;
            } else {
                boardToolType = TEDU_BOARD_TOOL_TYPE_OVAL;
            }
            
            [weakSelf.boardController setToolType:boardToolType];
        }];
    };
}
#pragma mark - 插入图片

- (UIImagePickerController *)imagePicker {
    if (!_imagePicker) {
        _imagePicker = [[UIImagePickerController alloc] init];
    }
    return _imagePicker;
}

- (void)selectBrushChaRuTuPianInteraction:(UIButton *)interaction {
    //self.imagePicker = [[UIImagePickerController alloc] init];
    self.imagePicker.delegate = self;
    self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    //弹出试图的参照试图
    //  弹出视图的显示样式
    self.imagePicker.modalPresentationStyle = UIPopoverArrowDirectionDown;
    
    //  1、弹出视图的大小
    self.imagePicker.preferredContentSize = CGSizeMake(300, 500);
    self.imagePicker.popoverPresentationController.sourceView = interaction;
    self.imagePicker.popoverPresentationController.sourceRect = interaction.bounds;
    //箭头得方向
    self.imagePicker.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionDown;
    self.imagePicker.popoverPresentationController.backgroundColor = [UIColor whiteColor];
    // 编辑模式
    self.imagePicker.allowsEditing=NO;
    [self presentViewController:self.imagePicker animated:YES completion:nil];
    
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {
    
    
    NSString *imagePath = @"";
    //通过UIImagePickerControllerMediaType判断返回的是照片还是视频
    NSString* type = [info objectForKey:UIImagePickerControllerMediaType];
    //如果返回的type等于kUTTypeImage，代表返回的是照片,并且需要判断当前相机使用的sourcetype是拍照还是相册
    if ([type isEqualToString:(NSString*)kUTTypeImage]&&picker.sourceType==UIImagePickerControllerSourceTypeCamera) {
        
    } else {
        
        
        UIImage *image = info[@"UIImagePickerControllerOriginalImage"];
        imagePath = [UIImage saveImageCommentImageStr:image];
        //获取图片的url
//        if (@available(iOS 11.0, *)) {
//            NSURL* url = [info objectForKey:UIImagePickerControllerImageURL];
//            imagePath = url.absoluteString;
//        } else {
//
//        }
    }
    //模态方式退出uiimagepickercontroller
    
    NSString *url =imagePath;
    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    __weak typeof(self) weakSelf = self;
    [self.imagePicker dismissViewControllerAnimated:YES completion:^{
        //得到图片，白板插入图片
//        [self.boardView updateBgImageWithPath:url mode:TXBoardImageModeFit succ:^(id obj) {
//
//        } failed:^(int errCode, NSString *errMsg) {
//
//        }];
        
        [NSObject executeRunloop:^{
            [MBProgressHUD mj_showMessage:@"正在插入图片..."];
        } afterDelay:0.1];
        [weakSelf.boardController setBackgroundImage:url mode:TEDU_BOARD_IMAGE_FIT_MODE_CENTER];
        
    }];
    
}


#pragma mark - 资源

- (SYBoardZiYuanViewController *)zyVC {
    if (!_zyVC) {
        _zyVC = [[SYBoardZiYuanViewController alloc] init];
    }
    return _zyVC;
}

- (void)selectBrushTutorResourceInfo:(NSMutableArray *)listArr interaction:(UIButton *)btn {
//    self.zyVC = [[SYBoardZiYuanViewController alloc] init];
    self.zyVC.dataListArr = listArr;
    //弹出试图的参照试图
    //  弹出视图的显示样式
    self.zyVC.modalPresentationStyle = UIModalPresentationPopover;
    //  1、弹出视图的大小
    self.zyVC.preferredContentSize = CGSizeMake(300, 500);
    self.zyVC.popoverPresentationController.sourceView = btn;
    self.zyVC.popoverPresentationController.sourceRect = btn.bounds;
    //箭头得方向
    self.zyVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionDown;
    self.zyVC.popoverPresentationController.backgroundColor = [UIColor whiteColor];
    self.zyVC.delegate  = self;
    [self presentViewController:self.zyVC animated:YES completion:nil];
    
    __weak typeof(self) weakSelf = self;
    self.zyVC.block = ^(NSString * _Nonnull path, SYInteractionZiYuanModel * _Nonnull zyModel, BOOL isDownload) {
        
        [weakSelf selectItemBlockPath:path ziyuanModel:zyModel isDownload:isDownload];
        [weakSelf.zyVC dismissViewControllerAnimated:YES completion:nil];
    };
    
}
- (void)selectItemBlockPath:(NSString *)path ziyuanModel:(SYInteractionZiYuanModel *)zyModel isDownload:(BOOL)isDownload {
    
    if (isDownload == YES) {//需要下载
        [self writeToCacheWithUrl:path];
    } else {
        NSString *message = nil;
        if (zyModel.suta == SYInteractionTypeTuPian) {//图片
            message = @"正在插入图片...";
            [_boardController setBackgroundImage:path mode:TEDU_BOARD_IMAGE_FIT_MODE_CENTER];
        } else if (zyModel.suta == SYInteractionTypeWenDang) {//文档

            _stateLab.text = @"正在对文件进行转码";
            TEduBoardTranscodeConfig *boardConfig = [[TEduBoardTranscodeConfig alloc] init];
            boardConfig.minResolution = @"2048 x 1536";
            boardConfig.isStaticPPT = YES;
            boardConfig.thumbnailResolution = @"1000x1000";
            
            [_boardController applyFileTranscode:path config:boardConfig];
            
        } else {//多余的
            
        }
    }
    
}
#pragma mark 写入缓存
- (void)writeToCacheWithUrl:(NSString *)urlStr
{
    _stateLab.hidden = NO;
    _stateLab.text = @"正在加载";
    __weak typeof(self) weakSelf = self;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
//        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]];
        //创建文件管理器
        NSFileManager *fileManager = [NSFileManager defaultManager];
        //获取document路径
        NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) objectAtIndex:0];
        [fileManager createDirectoryAtPath:[cachesPath stringByAppendingString:@"/Caches"] withIntermediateDirectories:YES attributes:nil error:nil];
        //写入路径
        NSString *path = [cachesPath stringByAppendingString:[NSString stringWithFormat:@"/%lu.%@",(unsigned long)[urlStr hash],urlStr.pathExtension]];
        
//        [data writeToFile:path atomically:YES];
        [self requestdataDownLoadFile:path urlstr:urlStr path:^(BOOL ispath, float progress) {
            if (ispath == YES) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    // 更新界面
                    [weakSelf fileTranscode:path];
                });
            } else {
                dispatch_async(dispatch_get_main_queue(), ^{
                    // 更新界面
                    weakSelf.stateLab.text = [NSString stringWithFormat:@"正在加载 %.2f%%",progress];
                });
                
            }
            
        }];
        
        
    });
    
    
    
}
- (void)requestdataDownLoadFile:(NSString *)filePath urlstr:(NSString *)urlStr path:(void(^)(BOOL ispath,float progress))path {
    
//    __weak typeof(self) weakSelf = self;
    [SYDownloadFile downloadFileWithUrl:urlStr success:^(id responseObject) {
        [MBProgressHUD mj_hideHUD];
        if (path) {
            path(YES,0);
        }
        
    } failure:^(NSError *error) {
//        [MBProgressHUD mj_hideHUD];
        [MBProgressHUD zr_showError:@"加载失败"];
        self.stateLab.text = @"加载失败";
        [NSObject executeRunloop:^{
            self.stateLab.hidden = YES;
        } afterDelay:1];
        
    } progress:^(float progress, long long bytesRead) {
        // [MBProgressHUD mj_hideHUDForView:self.view];
        
        if (path) {
            path(NO,progress);
        }
    } savePath:filePath];
    
    
}

- (void)fileTranscode:(NSString *)path {
    TEduBoardTranscodeConfig *boardConfig = [[TEduBoardTranscodeConfig alloc] init];
    boardConfig.minResolution = @"2048 x 1536";
    boardConfig.isStaticPPT = YES;
    boardConfig.thumbnailResolution = @"1000x1000";
    
    [_boardController applyFileTranscode:path config:boardConfig];
    _stateLab.text = @"正在对文件进行转码";
}


#pragma mark - 资源
#pragma mark - 根据辅导班级id选择资源
- (void)tutorResourceInfointeraction:(UIButton *)interView {
    if (self.isChat) {//从辅导聊天页面进来
        self.resourceVC = [[ResourceViewController alloc] init];
        self.resourceVC.isChar = YES;
        //弹出试图的参照试图
        //  弹出视图的显示样式
        self.resourceVC.modalPresentationStyle = UIModalPresentationPopover;
        //  1、弹出视图的大小
        self.resourceVC.preferredContentSize = CGSizeMake(800, 600);
        self.resourceVC.popoverPresentationController.sourceView = interView;
        self.resourceVC.popoverPresentationController.sourceRect = interView.bounds;
        //箭头得方向
        
        self.resourceVC.popoverPresentationController.backgroundColor = [UIColor whiteColor];
        
        [self presentViewController:self.resourceVC animated:YES completion:nil];
    } else {
        [MBProgressHUD mj_showLoading];
        if (self.templateId.length == 0) {
            self.templateId = @"0";
        }
        [SYRequestAPI bb_TutorResourceInfoTutorId:self.fdbId templateId:self.templateId success:^(NSMutableArray * _Nonnull dataListArr) {
            [MBProgressHUD mj_hideHUD];
            [self selectBrushTutorResourceInfo:dataListArr interaction:interView];
        } fail:^(NSError *error) {
            [MBProgressHUD mj_hideHUD];
            [MBProgressHUD zr_showError:error.domain];
        }];
    }
    
    
}

#pragma mark - 删除

- (SYBaiBanDeleteViewController *)deleteVC {
    if (!_deleteVC) {
        _deleteVC = [[SYBaiBanDeleteViewController alloc] init];
    }
    return _deleteVC;
}

- (void)tutorDeleteInteraction:(UIButton *)interView {
//    self.deleteVC = [[SYBaiBanDeleteViewController alloc] init];
    
    //弹出试图的参照试图
    //  弹出视图的显示样式
    self.deleteVC.modalPresentationStyle = UIModalPresentationPopover;
    //  1、弹出视图的大小
    self.deleteVC.preferredContentSize = CGSizeMake(160, 60);
    self.deleteVC.popoverPresentationController.sourceView = interView;
    self.deleteVC.popoverPresentationController.sourceRect = interView.bounds;
    //箭头得方向
    self.deleteVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionDown;
    self.deleteVC.popoverPresentationController.backgroundColor = [UIColor whiteColor];
    
    [self presentViewController:self.deleteVC animated:YES completion:nil];
    __weak typeof(self) weakSelf = self;
    self.deleteVC.block = ^(NSInteger index) { //0:删除 1：清空涂鸦 2：清空所有内容
        [weakSelf.deleteVC dismissViewControllerAnimated:YES completion:^{
            
        }];
        if (index == 0) {
            [weakSelf.boardController deleteBoard:@""];
        } else if (index == 1) {
            [weakSelf.boardController clearDraws];
        } else {
            [weakSelf.boardController clear];
        }
        
    };
}


#pragma mark - 获取白板所有文件列表
- (void)obtainBoarNumber {
//    self.numberArr = [_boardController getBoardList];
//    NSArray *dataListArr = [_boardController getFileInfoList];
    
    NSArray *fileArr = [self getFileList];
    _bbTopView.dataListArr = fileArr;
}
- (NSArray<SYBaiBanTopModel *> *)getFileList
{
    //获取当前白板页得id
    NSString *fileId = [_boardController getCurrentBoard];
    
    [self pageZhanShi];
    NSArray<TEduBoardFileInfo *> *files = [_boardController getFileInfoList];
    NSMutableArray *names = [NSMutableArray array];
    
    for (NSInteger i = 0; i<files.count; i++) {
        TEduBoardFileInfo *file = files[i];
        SYBaiBanTopModel *topModel = [[SYBaiBanTopModel alloc] init];
        if ([fileId containsString:file.fileId]) {
            topModel.isSelect = YES;
        } else {
            topModel.isSelect = NO;
        }
        NSString *name = nil;
        if (i == 0) {
            name = @"白板文件";
        } else {
            name = [NSString stringWithFormat:@"文件%ld",(long)i];
        }
        topModel.titleName = name;
        topModel.fileId = file.fileId;
        [names addObject:topModel];
    }
    
    return names;
}
//页码展示
- (void)pageZhanShi {
    //获取当前白板页得id
    NSString *fileId = [_boardController getCurrentBoard];
    NSArray *dataArr = [fileId componentsSeparatedByString:@"#"];
    NSString *dqFileid = [NSString stringWithFormat:@"#%@",dataArr.lastObject];
    //获取当前文件的数组
    self.numberArr = [_boardController getFileBoardList:dqFileid];
    //当前页面在总页面得位置
    NSInteger index = [self.numberArr indexOfObject:fileId];
    
    self.pageNumberLab.text = SJStringWithFormat(index+1);
    self.zongNumberLab.text = SJStringWithFormat(self.numberArr.count);
    
}


//获取当前白板页得id
- (NSString *)getCurrentBoard
{
    return [_boardController getCurrentBoard];
}


#pragma mark - 接受到通知
- (void)onDowloadPPTNotification:(NSNotification *)not {
    NSDictionary *dict = not.userInfo;
    NSString *path = [dict nilObjectForKey:@"filePath"];
     [self.resourceVC dismissViewControllerAnimated:YES completion:nil];
    //上传文件
    [MBProgressHUD mj_showMessage:@"正在对文件进行转码..."];
    TEduBoardTranscodeConfig *boardConfig = [[TEduBoardTranscodeConfig alloc] init];
    boardConfig.minResolution = @"2048 x 1536";
    boardConfig.isStaticPPT = YES;
    boardConfig.thumbnailResolution = @"1000x1000";
    
    [_boardController applyFileTranscode:path config:boardConfig];
    
   
    
}


#pragma mark - 腾讯im
- (void)onNewMessageNotification:(NSNotification *)no {
    
    NSArray<TIMMessage *> *msgs = no.object;
    for (TIMMessage *msg in msgs) {
        for (int i = 0; i < msg.elemCount; i++) {
            TIMElem * elem = [msg getElem:i];
            if ([elem isKindOfClass:[TIMCustomElem class]]) {//自定义消息
                TIMCustomElem *custom_elem = (TIMCustomElem *)elem;
                [self getEleCustomEle:custom_elem];
                
            }
        }
        
    }
    
}
- (void)getEleCustomEle:(TIMCustomElem *)elem {
    
    NSDictionary *dictionary = [NSObject convertJsonStringToNSData:elem.data];
    
    NSInteger typeStr = [[dictionary nilObjectForKey:@"type"] integerValue];
    
    switch (typeStr) {
        case 440://学生申请发言
            [self shenQingFaYanDict:dictionary];
            break;
        case 415://学生在线
            
            [self zaiXianShenQing:dictionary];
            
            break;
        case 410://学生进入房间
        case 420://退出会议室
            
            break;
            
        default:
            break;
    }
}
//在线申请
- (void)zaiXianShenQing:(NSDictionary *)dictionary {
    //    NSString *body = [dictionary nilObjectForKey:@"body"];
    //    NSDictionary *bodyDict = [NSObject convertJsonString:body];
    //    NSString * enterStr = [dictionary nilObjectForKey:@"from"];
    //    _studentsView.enterStr = enterStr;
}
//申请发言
- (void)shenQingFaYanDict:(NSDictionary *)dictionary {
    NSString *body = [dictionary nilObjectForKey:@"body"];
    NSDictionary *bodyDict = [NSObject convertJsonString:body];
    
    NSString *nameStr = [NSString stringWithFormat:@"%@申请发言",[bodyDict nilObjectForKey:@"name"]];
    
    __weak typeof(self) weakSelf = self;
    [self showCancleAlertWithTitle:nameStr msg:@"" handler:^(NSInteger index) {
        if (index == 1) {//允许
            [weakSelf sendMessageBodyDic:dictionary isCanSpeak:1];
        } else {//不允许
            [weakSelf sendMessageBodyDic:dictionary isCanSpeak:0];
        }
    }];
    
}
/**
 自定义消息发言
 
 @param bodyDic 申请发言人的数据
 @param isSpeak 是否允许发言 yes 允许  no
 */
- (void)sendMessageBodyDic:(NSDictionary *)bodyDic isCanSpeak:(NSInteger)isSpeak {
    
    //    NSString *name = [bodyDic nilObjectForKey:@"name"];//名字
    NSString *voipAccount = [NSString stringWithFormat:@"%@",[bodyDic nilObjectForKey:@"from"]];//id
    NSDictionary *messageDict = @{@"type":SJStringWithFormat(kGFYunXuType),
                                  @"body":SJStringWithFormat(isSpeak),
                                  @"from":self.imId,//老师的id
                                  @"sendTime":@"0",
                                  @"membertype":@"1",
                                  @"txAccount":voipAccount
                                  };
    [self sendMessageStr:[NSObject convertToJsonData:messageDict] fids:voipAccount isSpak:isSpeak];
}
#pragma mark - 发送消息的方法
- (void)sendMessageStr:(NSString *)message fids:(NSString *)fid isSpak:(NSInteger)isSpak {
    // 转换为 NSData
    NSData *data = [message dataUsingEncoding:NSUTF8StringEncoding];
    TIMCustomElem * custom_elem = [[TIMCustomElem alloc] init];
    [custom_elem setData:data];
    TIMMessage * msg = [[TIMMessage alloc] init];
    [msg addElem:custom_elem];
    [self.conversation sendMessage:msg succ:^(){
        if (fid.length > 0) {
            [self.studentsView isFids:fid isSpeak:isSpak];
        }
        
        //有学生进入直播室
        NSLog(@"SendMsg Succ");
    }fail:^(int code, NSString * err) {
        NSLog(@"SendMsg Failed:%d->%@", code, err);
    }];
}
#pragma mark - 发送结束上课的消息
- (void)imOverCourse {
    NSDictionary *messageDict = @{@"type":SJStringWithFormat(kGFJieShuType),
                                  @"body":self.roomId,
                                  @"from":self.imId,//老师的id
                                  @"sendTime":@"0",
                                  @"membertype":@"1",
                                  //@"txAccount":studentModel.UserIMID
                                  };
    
    [self sendMessageStr:[NSObject convertToJsonData:messageDict] fids:@"" isSpak:1];
    // 退出课堂
//    [[TICManager sharedInstance] quitClassroomSucc:^{
//        //        [[JMToast sharedToast] showDialogWithMsg:@"退房成功"];
//        [MBProgressHUD zr_showError:@"退出课堂成功"];
//    } failed:^(NSString *module, int errId, NSString *errMsg) {
//        //        [[JMToast sharedToast] showDialogWithMsg:[NSString stringWithFormat:@"退出房间失败：%d-%@", errId, errMsg]];
//        [MBProgressHUD zr_showError:[NSString stringWithFormat:@"退出房间失败:%@",errMsg]];
//    }];
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
#pragma mark - 学生列表的代理
#pragma mark - SYIMStudentsViewDelegate
- (void)imStudentsViewInteractionStudentModel:(SYInteractionStudentModel *)studentModel reserved:(id)obj {
    BOOL isMake = !studentModel.isMake;
    NSDictionary *messageDict = @{@"type":SJStringWithFormat(kGFYunXuType),
                                  @"body":SJStringWithFormat(isMake),
                                  @"from":self.imId,//老师的id
                                  @"sendTime":@"0",
                                  @"membertype":@"1",
                                  @"txAccount":studentModel.UserIMID
                                  };
    [self sendMessageStr:[NSObject convertToJsonData:messageDict] fids:studentModel.UserIMID isSpak:isMake];
}

//接受群组消息id
- (void)onTICRecvGroupCustomMessage:(NSData *)data groupId:(NSString *)groupId fromUserId:(NSString *)fromUserId {
    
}


//收到im信息回掉
- (void)onTICRecvMessage:(TIMMessage *)message {
    

}
#pragma mark - -
#pragma mark - 上课调用的接口
//老师上课的时候调用
- (void)teacherClass {
    __weak typeof(self) weakSelf = self;
    [SYRequestAPI bb_TutorServiceJoinClassLessonAccountId:self.accountId tutorRecordId:self.tutorRecordId success:^(id  _Nonnull dataList) {
        weakSelf.teacherRecordId = [dataList integerValue];
        [weakSelf updateServicesTeacherRecordId:weakSelf.tutorRecordId  status:@"2"];
        
    } fail:^(NSError *error) {
        
    }];
}
//更新上课状态
- (void)updateServicesTeacherRecordId:(NSString *)recordId status:(NSString *)status {
    [SYRequestAPI bb_TutorServiceSetTutorInfoStatusTutorRecordId:recordId status:status success:^(id  _Nonnull dataList) {
        
    } fail:^(NSError *error) {
        
    }];
}
// 初始化白板成功后 老师上课推送调用接口
- (void)tutorClassPushMsg {
    [SYRequestAPI bb_TutorClassServicePushTutorId:self.fdbId TutorRecordId:self.tutorRecordId RoomID:self.roomId RoomIMID:self.tecentRoom RoomName:self.tutorRecordName TeaAccount:_userName success:^(BOOL isSuccess) {
        
    } fail:^(NSError *error) {
        
    }];
}

//老师下课时调用
- (void)teacherEnterClass {
    [MBProgressHUD mj_showMessage:@"正在退出" toView:self.view];
    __weak typeof(self) weakSelf = self;
    [SYRequestAPI bb_TutorServiceExitClassLessonTeacherRecordId:SJStringWithFormat(_teacherRecordId) success:^(id  _Nonnull dataList) {
        [weakSelf updateXiaKeTeacherRecordId:weakSelf.tutorRecordId  status:@"1"];
        [MBProgressHUD mj_hideHUDForView:self.view];
    } fail:^(NSError *error) {
        [weakSelf updateXiaKeTeacherRecordId:weakSelf.tutorRecordId  status:@"1"];
        [MBProgressHUD mj_hideHUDForView:self.view];
        
    }];
}
- (void)updateXiaKeTeacherRecordId:(NSString *)recordId status:(NSString *)status {
    [SYRequestAPI bb_TutorServiceSetTutorInfoStatusTutorRecordId:recordId status:status success:^(id  _Nonnull dataList) {
        //发送退出课堂得消息
        [self imOverCourse];
        
        [[TICManager sharedInstance] quitClassroom:NO callback:^(TICModule module, int code, NSString *desc) {
            if(code == 0){
                //退出课堂成功
                [self dismissViewControllerAnimated:YES completion:^{
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"SYInteractionViewControllerNotification" object:nil];
                }];
            }
            else{
                //退出课堂失败
                
            }
        }];
        
    } fail:^(NSError *error) {
        //发送退出课堂得消息
        [self imOverCourse];
        [[TICManager sharedInstance] quitClassroom:NO callback:^(TICModule module, int code, NSString *desc) {
            if(code == 0){
                //退出课堂成功
                [self dismissViewControllerAnimated:YES completion:^{
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"SYInteractionViewControllerNotification" object:nil];
                }];
            }
            else{
                //退出课堂失败
            }
        }];
    }];
}
//开始录制视频
- (void)startRecord {
    __weak typeof(self) weakSelf = self;
    [SYRequestAPI bb_TutorStartRecordRoomId:self.roomId success:^(BOOL isSuccess, NSString * _Nonnull info) {
        weakSelf.infoId = info;
        if (weakSelf.isChat) {
            [MBProgressHUD mj_showSuccess:@"开启成功"];
            [self.starRecordingBtn setTitle:@" 暂停 " forState:UIControlStateNormal];
//            self.starRecordingBtn.userInteractionEnabled = NO;
            _luzhiIndex = 1; //暂停

            //开始计时
            [self.timerView startTimer];
        }
    } fail:^(NSError *error) {
//        [MBProgressHUD mj_showSuccess:error.domain];
        if (error.domain.length > 0) {
            [MBProgressHUD mj_showError:error.domain];
        } else {
            [MBProgressHUD mj_showError:@"开启失败，请稍后重试"];
        }
    }];
}
//暂停
- (void)pauseRecord {
 
    [MBProgressHUD mj_showLoading];
    [SYRequestAPI bb_TutorPauseRecordTaskId:self.infoId success:^(NSString * _Nonnull pathUrl) {
        [MBProgressHUD mj_hideHUD];
        [MBProgressHUD mj_showSuccess:pathUrl];
        _luzhiIndex = 2;

        [self.starRecordingBtn setTitle:@"恢复录制" forState:UIControlStateNormal];
        //暂停
        [self.timerView zantingTimer];
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUD];
        
    }];
    
}
//恢复
- (void)huifuRecord {
    [MBProgressHUD mj_showLoading];
    [SYRequestAPI bb_TutorResumeRecordTask:self.infoId success:^(NSString * _Nonnull pathUrl) {
        [MBProgressHUD mj_hideHUD];
        [MBProgressHUD mj_showSuccess:pathUrl];
        _luzhiIndex = 1;

        [self.starRecordingBtn setTitle:@" 暂停 " forState:UIControlStateNormal];
        //暂停
        [self.timerView huifuTimer];
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUD];
    }];
    
}



//结束录制视频
- (void)stopRecord {
    if (self.infoId) {
        [SYRequestAPI bb_TutorStopRecordInfo:self.infoId success:^(BOOL isSuccess, NSString * _Nonnull info) {
            
        } fail:^(NSError *error) {
            
        }];
    }
    
}




#pragma mark - 检测网络
- (void)onNetworkQuality: (TRTCQualityInfo*)localQuality remoteQuality:(NSArray<TRTCQualityInfo*>*)remoteQuality {
    NSInteger index = localQuality.quality;
    UIColor *color;//颜色
    NSString *titleStr;//标识
    if (index == 1 || index == 2 ) {
        color = [UIColor colorWithHexString:@"#46cb04"];
        titleStr = @"较好";
    } else if (index == 3 || index == 4) {
        color = [UIColor colorWithHexString:@"#46cb04"];
        titleStr = @"良好";
    } else if (index == 5 || index == 5) {
        color = [UIColor colorWithHexString:@"#d81e06"];
        titleStr = @"差劲";
    } else {
        color = [UIColor colorWithHexString:@"#999999"];
        titleStr = @"连接中";
    }
    
    _wifiLab.text = titleStr;
    _wifiLab.textColor = color;
    
}



@end
